package thinkingInJava.generics;
// page 461
//: containers/CollectionDataTest.java
import java.util.*;
import thinkingInJava.arrays.*;

class Government implements Generator<String> {
    String[] foundation = ("strange women lying in ponds " +
        "distributing swords is no basis for a system of " +
        "government").split(" ");
    private int index;
    public String next() { return foundation[index++]; }
}

public class CollectionDataTest {
    public static void main(String[] args) {
        Set<String> set = new LinkedHashSet<String>(
            new CollectionData<String>(new Government(), 15)); // CollectionData 为 适配器模式，将Generator 适配到 Collection
        System.out.println(set);
        // Using the convenience method:
        set.addAll(CollectionData.list(new Government(), 15));
        System.out.println(set);
    }
} /* Output: 输出顺序与插入顺序相同 因为 LinkedHashSet 维护的是保持插入顺序链接列表
[strange, women, lying, in, ponds, distributing, swords, is, no, basis, for, a, system, of, government]
[strange, women, lying, in, ponds, distributing, swords, is, no, basis, for, a, system, of, government]
 *///:~
